package model

import (
	"gorm.io/gorm"
	"live-broadcast_07_23/global"
	"time"
)

type Upload struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:图片ID;primaryKey;not null;"  form:"id" json:"id"`                                          // 图片ID
	Name      string         `gorm:"column:name;type:varchar(255);comment:原始文件名;not null;"  form:"name" json:"name"`                                              // 原始文件名
	OssUrl    string         `gorm:"column:oss_url;type:varchar(255);comment:OSS URL;not null;"  json:"oss_url" json:"oss_url"`                                   // OSS URL
	Size      float64        `gorm:"column:size;type:double;comment:大小;not null;"  form:"size" json:"size"`                                                       // 大小
	UserId    int8           `gorm:"column:user_id;type:tinyint(1);comment:上传用户ID;not null;"  form:"user_id" json:"user_id"`                                      // 上传用户ID
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);comment:上传时间;not null;default:CURRENT_TIMESTAMP(3);"  form:"created_at" json:"created_at"` // 上传时间
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);"  form:"updated_at" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;"  form:"deleted_at" json:"deleted_at"`
}

func (u Upload) TableName() string {
	return "upload"
}

func (u *Upload) DeleteUpload() {
	global.DB.Delete(&u)
}

func (u *Upload) ListUpload() (upload []Upload, err error) {
	err = global.DB.Find(&upload).Error
	return
}

func (u *Upload) GetOneUpload() {
	global.DB.Where("id = ?", u.Id).Limit(1).Find(&u)
}
